//
//  DetailsTopView.m
//  BestPurchase
//
//  Created by ZSMAC on 2018/10/11.
//  Copyright © 2018年 张帅. All rights reserved.
//

#import "DetailsTopView.h"
@interface DetailsTopView ()<UIScrollViewDelegate>
@property(nonatomic,strong)UIScrollView * secrollView;
@property(nonatomic,strong)UILabel * showPageLabel;
@end
@implementation DetailsTopView

- (instancetype)initWithFrame:(CGRect)frame {
    self=[super initWithFrame:frame];
    if (self) {
        [self uiConfigure];
    }
    return self;
}
- (void)uiConfigure {
    self.secrollView=[[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.width, self.height)];
    self.secrollView.pagingEnabled=YES;
    self.secrollView.showsVerticalScrollIndicator=NO;
    self.secrollView.showsHorizontalScrollIndicator=NO;
    self.secrollView.delegate=self;
    [self addSubview:self.secrollView];
    
    _showPageLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.width-45-15, self.height-35, 45, 30)];
    _showPageLabel.font=Font(15);
    _showPageLabel.textAlignment=NSTextAlignmentCenter;
    _showPageLabel.textColor=[UIColor whiteColor];
    _showPageLabel.layer.cornerRadius=5;
    _showPageLabel.layer.masksToBounds=YES;
    _showPageLabel.text=@"1/1";
    _showPageLabel.backgroundColor=[MyRGB(153, 153, 153) colorWithAlphaComponent:0.5];
    [self addSubview:_showPageLabel];
    
}
- (void)setImageUrls:(NSArray<NSString *> *)imageUrls {
    _imageUrls=imageUrls;
    int i=0;
    for (NSString *urlStr in _imageUrls) {
        UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(i*self.secrollView.width, 0, self.secrollView.width, self.secrollView.height)];
        imageView.backgroundColor=[UIColor colorWithRed: arc4random_uniform(256)/255.0f green: arc4random_uniform(256)/255.0f blue: arc4random_uniform(256)/255.0f alpha:1];
        UIImage * placeholderImage=[UIImage imageNamed:@"placeholderImage"];//站位
        [imageView sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:placeholderImage];
        imageView.contentMode=UIViewContentModeScaleAspectFill;
        imageView.userInteractionEnabled=YES;
        [self.secrollView addSubview:imageView];
        i++;
    }
     self.secrollView.contentSize=CGSizeMake(self.imageUrls.count*self.secrollView.width, 0);
     _showPageLabel.text=[NSString stringWithFormat:@"1/%ld",(long)self.imageUrls.count];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
    int page=  scrollView.contentOffset.x/scrollView.width;
    page+=1;
    _showPageLabel.text=[NSString stringWithFormat:@"%ld/%ld",(long)page,(long)self.imageUrls.count];
}
@end
